package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.expcetions.CommonException;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.constants.RedisConstants;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IRegionServeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;


/**
 * \* User: chy
 * \* Date: 2025/9/24  15:07
 * \* Description:
 * \
 */
@RestController
@RequestMapping("/operation/serve")
@RequiredArgsConstructor
@Slf4j
public class RegionServeController {

    private final IRegionServeService regionServeService;
    /**
     * 区域服务分页查询
     *
     * @param reqDTO
     * @return
     */
    @GetMapping("/page")
    public PageResult<ServeResDTO> queryRegionServePage(ServePageQueryReqDTO reqDTO) {
        log.info("区域服务分页查询..........");
        PageResult<ServeResDTO> pageResult = regionServeService.queryRegionServePage(reqDTO);
        return pageResult;
    }

    /**
     * 批量新增区域服务
     *
     * @param resDTO
     */
    @PostMapping("/batch")
    public void batchAddRegionServe(@RequestBody List<ServeUpsertReqDTO> resDTO) {
        log.info("批量新增服务..........");
        regionServeService.batchAddRegionServe(resDTO);
    }

    /**
     * 根据serveId修改价格
     *
     * @param id
     * @param price
     */
    @PutMapping("/{id}")
    public void updateRegionServe(@PathVariable Long id,
                                  @RequestParam BigDecimal price) {
        log.info("修改服务价格..........");
        regionServeService.updateServePrice(id, price);
    }
    /**
     * 上架服务
     *
     * @param id
     */
    @PutMapping("/onSale/{id}")
    public void onSaleRegionServe(@PathVariable Long id) {
        log.info("上架服务..........");
        regionServeService.onSaleSaleStatus(id);
    }
    /**
     * 下架服务
     *
     * @param id
     */
    @PutMapping("/offSale/{id}")
    public void offSaleRegionServe(@PathVariable Long id) {
        log.info("下架服务..........");
        regionServeService.offSaleSaleStatus(id);
    }
    /**
     * 删除服务
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    public void deleteRegionServe(@PathVariable Long id) {
        log.info("删除服务id:{}..........", id);
        boolean result = regionServeService.removeById(id);
        if (!result) {
            throw new CommonException("删除服务失败");
        }
    }

    /**
     * 更新服务为热门服务
     *
     * @param id
     */
    @PutMapping("/onHot/{id}")
    public void updateOnHot(@PathVariable Long id){
        log.info("更新服务为热门服务id:{}..........", id);
        regionServeService.updateOnHot(id);
    }
    /**
     * 更新服务为冷门服务
     *
     * @param id
     */
    @PutMapping("/offHot/{id}")
    public void updateOffHot(@PathVariable Long id){
        log.info("更新服务为冷门服务id:{}..........", id);
        regionServeService.updateOffHot(id);
    }
}
